/*
 * PointBrush.java	1.0  01/02/2006
 * PointBrush.java	2.0  10/02/2008
 *
 * This class is the brush drawing point patterns
 * Author:    Isabelle Bichindaritz
 *
 */

import java.awt.*;
import java.nio.*;
import javax.media.opengl.*;
import javax.media.opengl.glu.*;

public class DotBrush extends Brush {

    private double previousX = Double.NEGATIVE_INFINITY;
    private double previousY = Double.NEGATIVE_INFINITY;

    public void brushBegin(Point source, Point target, GLAutoDrawable drawable) {
        // initiates brush movement by setting the point size from Painter slider
        int size = Painter.size;

        final GL gl = drawable.getGL();
        final GLU glu = new GLU();
        //System.out.println ("PointBrush brushBegin Size=" + size);
        gl.glPointSize((float) size);
        gl.glLineWidth((float) Painter.size);
        gl.glEnable(GL.GL_LINE_STIPPLE);
        gl.glLineStipple(Painter.fill, (short) 0x0001);     // Plot a dashed, double-width polyline.
        brushMove(source, target, drawable);
    }

    public void brushMove(Point source, Point target, GLAutoDrawable drawable) {
        // continues brush movement by copying the color from the original picture
        // to the current mouse position
        final GL gl = drawable.getGL();
        final GLU glu = new GLU();
        gl.glBegin(GL.GL_LINE_STRIP);

        if (Painter.imageRGBA == null) {
            System.out.println("PointBrush picture is NULL");
        } else {
            setColor(source, drawable);
            if (previousX != Double.NEGATIVE_INFINITY
                    | previousY != Double.NEGATIVE_INFINITY) {
                gl.glVertex2d(previousX, previousY);
            } else {
                previousX = target.getX();
                previousY = target.getY();
            }
            gl.glVertex2d(target.getX(), target.getY());
            previousX = target.getX();
            previousY = target.getY();
        }
        gl.glEnd();
    }

    public void brushEnd(Point source, Point target) {
        // ends the brush movement
        int size = Painter.size;

        previousX = Double.NEGATIVE_INFINITY;
        previousY = Double.NEGATIVE_INFINITY;
    }
    //----------------------------------------------------
    // This brush draws points
    //----------------------------------------------------
} // end PointBrush class

